package com.tjnu.losca.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.tjnu.losca.Vo.ResponseVO;
import com.tjnu.losca.service.ICategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author losca
 * @since 2022-02-13
 */
@RestController
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    ICategoryService categoryService;
    @GetMapping("/getCategories")
    public ResponseVO<IPage> getCategories(@RequestParam(defaultValue = "1")Integer pageNum,
                                    @RequestParam(defaultValue = "8")Integer pageSize,
                                    @RequestParam(defaultValue = "")String search){
        return ResponseVO.success(categoryService.getAll(pageNum, pageSize, search));
    }
    @GetMapping("/getData")
    public ResponseVO<HashMap> getData(){
        return ResponseVO.success(categoryService.getData());
    }
    @PostMapping("/del")
    public ResponseVO<Boolean> del(String cId){
        return ResponseVO.success(categoryService.del(cId));
    }

    @PostMapping("/rec")
    public ResponseVO<Boolean> rec(String cId){
        return ResponseVO.success(categoryService.rec(cId));
    }
    @PostMapping("/mulDel")
    public ResponseVO<Boolean> mulDel(String[] cIds){
        System.out.println(cIds);
        return ResponseVO.success(categoryService.mulDel(cIds));
    }
    @PostMapping("/add")
    public ResponseVO<Boolean> add(Integer categoryId,String name){
        return ResponseVO.success(categoryService.add(categoryId,name));
    }

    @GetMapping("/categoryTable")
    public ResponseVO<List> categoryTable(){
        return ResponseVO.success(categoryService.categoryTable());
    }

}
